package controller;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

public class RelNofflowServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException {

		try {
			request.getRequestDispatcher("rel_nofflow.jsp").forward(request,
					response);
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		
		response.setCharacterEncoding("utf-8");
		String str = request.getParameter("text");
		Document document = Jsoup.parse(str);
		for (int i = 0; i < document.select("a").size(); i++) {
			document.select("a").get(i).attr("rel","nofollow");
		}
		
		request.setAttribute("str", document.select("body").html());
		
		try {
			request.getRequestDispatcher("rel_nofflow.jsp").forward(request,
					response);
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
}
